<template>
  <div>
    <div class="head">
      <div class="left">
        <img src="@/assets/fanhui@2x.png" alt="" @click="backPre" />
        <!-- <span>教学资料 ({{itemInfo.majorName}})</span> -->
      </div>
      <div class="text">
        <span style="display: inline-block">教学资料</span>
        <span style="display: block">({{ itemInfo.majorName }})</span>
      </div>
      <div class="middle">
        <span>课程{{ Number(num) + 1 }}：{{ itemInfo.name }}</span>
      </div>
      <span></span>
    </div>
    <div class="container">
      <div class="list">
        <div class="title">
          <span>教务资料</span>
        </div>
        <div class="listContent">
          <!-- <el-menu>
            <el-submenu index="1"  v-for="item in dataList" :key="item.id">
        <template slot="title">
        {{item.name}}
          </template>
          <div v-if="item.children">
            {{item.children}}
          </div>
      </el-submenu>
      </el-menu> -->
          <el-tree
            :data="dataList"
            :props="defaultProps"
            node-key="id"
            :expand-on-click-node="false"
          >
            <span class="custom-tree-node" slot-scope="{ node, data }">
              <span>{{ node.label }}</span>
              <a :href="data.url" target="_blank" v-if="data.url !== null">
                <img src="@/assets/download1.png" alt="" class="listImg" />
              </a>
            </span>
          </el-tree>
          <!-- <el-tree :props="props" :load="loadNode" lazy show-checkbox>
          </el-tree> -->
        </div>
      </div>
      <div class="video">
        <div class="title">
          <span>课件/视频</span>
        </div>
        <div class="listContent">
          <el-tree
            :data="dataList2"
            :props="defaultProps"
            node-key="id"
            :expand-on-click-node="false"
          >
            <span class="custom-tree-node" slot-scope="{ node, data }">
              <span>{{ node.label }}</span>
              <a :href="data.url" target="_blank" v-if="data.url !== null">
                <img src="@/assets/download1.png" alt="" class="listImg" />
              </a>
            </span>
          </el-tree>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getMaterial, uploadMaterial } from '@/api/lessonPreparation/myLesson';
export default {
  data() {
    return {
      itemInfo: {},
      num: '',
      dataList: [],
      defaultProps: {
        label: 'name',
        children: 'children'
      },
      dataList2: []
    };
  },
  methods: {
    async getData() {
      this.num = this.$route.query.index;
      const res = await getMaterial({id: this.$route.query.id});
      // console.log(res);
      this.itemInfo = res.data;
      this.dataList = res.data.projectmaterialFileVoList;
      this.dataList2 = res.data.projectmaterialFileVoTypeList;
      // this.EducationalList = res.data.projectmaterialFileVoList;
      // console.log(this.dataList);
    },
    // 返回上一页
    backPre() {
      this.$router.replace('/lesson');
    },
    // 点击下载
    async uploadFile(val) {
      // console.log(val);
      if (val.url) {
        const res = await uploadMaterial({url: val.url, disposition: 'attachment'});
        // console.log(res);
        if (res.code === 200) {
          this.$notify({
            title: '下载成功',
            message: '文件下载成功',
            type: 'success'
          });
        } else {
          this.$notify.error({
            title: '下载失败',
            message: '文件下载失败'
          });
        }
      } else {
        this.$notify.error({
          title: '下载失败',
          message: '暂无相关资料'
        });
      }
    }
  },
  created() {
    this.getData();
  }
};
</script>

<style lang="less" scoped>
.head {
  height: 190px;
  width: 98%;
  margin: 0 auto;
  box-sizing: border-box;
  background-image: url("../../../assets/Lessonpreparationbg.png");
  background-size: contain;
  background-repeat: no-repeat;
  // padding-top: 80px;
  display: flex;
  // justify-content:space-between;
  align-items: center;
  .left {
    padding-left: 30px;
    box-sizing: border-box;
    padding-top: 20px;
    img {
      height: 46px;
      width: 72px;
      margin-right: 25px;
      // margin-top: 10px;
    }
  }
  .text {
    // padding-top: 10px;
    padding-left: 10px;
    span {
      font-size: 28px;
      padding-top: 10px;
      font-weight: 500;
      color: #ffffff;
    }
  }
  .middle {
    box-sizing: border-box;
    margin-left: 356px;
    padding-top: 10px;
    span {
      font-size: 26px;
      font-weight: 500;
      color: #ffffff;
    }
  }
}
.container {
  display: flex;
  padding-left: 30px;
  box-sizing: border-box;
  .list,
  .video {
    width: 912px;
    height: 600px;
    background: #ffffff;
    box-shadow: 2px 2px 4px 0px rgba(153, 153, 153, 0.5);
    border-radius: 8px;
  }
  .list,
  .video {
    .title {
      span {
        display: inline-block;
        width: 112px;
        height: 45px;
        background: #e8f8fb;
        border-radius: 0px 0px 8px 0px;
        font-size: 16px;
        font-weight: 500;
        color: #2fc0e0;
        text-align: center;
        line-height: 45px;
      }
    }
  }
  .list {
    margin-right: 40px;
  }
  .listContent {
    margin: 0;
    padding: 0;
    overflow-y: scroll;
    height: 500px;
    .listImg {
      height: 37px;
      width: 37px;
      position: absolute;
      right: 50px;
      top: 0px;
      display: none;
    }
  }
}
.custom-tree-node {
  // flex: 1;
  // display: flex;
  // align-items: center;
  // justify-content: space-between;
  font-size: 14px;
  // height: 80px !important;
  padding-right: 8px;
}
/deep/.el-tree-node__content {
  height: 45px !important;
  position: relative;
  border-bottom: 1px solid #f2f2f2;
}
/deep/.el-tree-node__content:hover .listImg {
  display: block;
}
</style>
